<%@ Import Namespace="System.IO" %>
<script runat="server">
	Sub Page_Load( sender as object, e as EventArgs)
		if not Request("dir") is nothing  then
			DirName.Value = Request("dir")
		end if
	End Sub
</script>

<h3>ASP.NET Directory Browser</h3>

<form runat="server" action="default.aspx">
	Directory Name: <input type="text" id="DirName" size="60" 
				value="c:\program files\internet explorer" runat="server" >
	<input type="submit" value="List">
</form>

<%
	dim dir as DirectoryInfo
	dim anchor as string

	' Get the information about the selected directory
	
	dir = new DirectoryInfo( DirName.Value )

	Response.Write("<h3>Sub Directories in " + DirName.Value + "</h3>")

	Response.Write("<table>")
	Response.Write("<tr bgcolor=cornflowerblue>")
 	Response.Write("<td>")
	Response.Write( "Name" )
 	Response.Write("<td>")
	Response.Write( "Last Modified" )
	Response.Write("</tr>")

	dim SubDir as DirectoryInfo

	for each SubDir in dir.GetDirectories() 
		anchor = "<a href='" & "default.aspx?dir=" & SubDir.FullName & "'>" + SubDir.Name & "</a>"
		Response.Write("<tr>")
 		Response.Write("<td>")
		Response.Write( anchor )
 		Response.Write("<td>")
		Response.Write( SubDir.LastWriteTime )
		Response.Write("</tr>")
	next

	Response.Write("</table>")

	if ( not dir.Parent is nothing ) then
		anchor = "<a href='" & "default.aspx?dir=" & dir.Parent.FullName & "'>" & dir.Parent.FullName & "</a>"
		Response.Write("<p>Parent directory is " + anchor )
	end if
	
	Response.Write("<h3>Files in " + DirName.Value + "</h3>")

	Response.Write("<table>")
	Response.Write("<tr bgcolor=cornflowerblue>")
 	Response.Write("<td>")
	Response.Write( "Filename" )
 	Response.Write("<td>")
	Response.Write( "Last Modified" )
 	Response.Write("<td>")
	Response.Write( "Size" )
	Response.Write("</tr>")
	
	dim f as FileInfo

	for each f in dir.GetFiles()
		Response.Write("<tr>")
 		Response.Write("<td>")
		Response.Write( f.Name )
		
		if ( (f.Attributes and FileAttributes.ReadOnly) <> 0 ) then
			Response.Write(" (read only)")
		end if

		if ( (f.Attributes and FileAttributes.Hidden) <> 0 ) then
			Response.Write(" (hidden)")
		end if

		if ( (f.Attributes and FileAttributes.System) <> 0 ) then
			Response.Write(" (system)")
		end if

		if ( (f.Attributes and FileAttributes.Archive) <> 0 ) then
			Response.Write(" (archive)")
		end if

		
		Response.Write( f.Attributes.ToString() )

 		Response.Write("<td>")
		Response.Write( f.LastWriteTime )
 		Response.Write("<td>")
		Response.Write( f.Length.ToString() )
	
		Response.Write("</tr>")
	next

	Response.Write("</table>")
%>

